# Prepend templates
if [[ ${+commands[git]} -ne 0 && -x ${commands[git]} ]]; then
  HAS_GIT=1
else
  HAS_GIT=0
  print -PR '<%= okay %>Git not found, setting degit as the default in your .zshrc file.'
  # Also set degit as the defaul in the current shell session, used by the install step.
  zstyle ':zim:zmodule' use 'degit'
fi
<%= render_templates("src/templates/*") %>
for ZTEMPLATE in ${(k)ZTEMPLATES}; do
  USER_FILE=${${:-<%= home %>/.${ZTEMPLATE}}:A}
  if ERR=$(command mv -f =(
    if [[ ${ZTEMPLATE} == zshrc && ${HAS_GIT} -eq 0 ]]; then
      print -R "${(F)${(@f)ZTEMPLATES[${ZTEMPLATE}]}/(#b)\#(zstyle*degit*)/$match[1]}"
    else
      print -R ${ZTEMPLATES[${ZTEMPLATE}]}
    fi
    if [[ -e ${USER_FILE} ]] cat ${USER_FILE}
  ) ${USER_FILE} 2>&1); then
    print -PR "<%= okay %>Prepended Zim template to %B${USER_FILE}%b"
  else
    print -u2 -PlR "%F{red}<%= error %>Error prepending Zim template to %B${USER_FILE}%b%f" ${ERR}
    return 1
  fi
done
